home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 6 / ddj_cspc.zip / POOLE.LST < prev    next >
File List  |  1989-11-21  |  12KB  |  503 lines

  1. _C PRINTER FOR VMS AND UNIX_
  2. by Kevin E. Poole
  3.  
  4. SIDEBAR TO _AUTOMATIC MODULE CONTROL REVISITED_ BY RON WINTER
  5.  
  6. [LISTING ONE]
  7.  
  8. !
  9. !  VAX/VMS MMS Description File 
  10. !
  11. ! DEFINITIONS:
  12. H = cpheader.h
  13. !
  14. ! CP
  15. !
  16. cp DEPENDS_ON cp.obj cpbuild.obj cpfuncts.obj cpinput.obj
  17.     LINK/EXEC=cp cp.obj,cpbuild.obj,cpfuncts.obj,cpinput.obj
  18.     PURGE *.obj, *.exe
  19.  
  20. cp.obj DEPENDS_ON $(H) cp.c
  21.     cc cp.c
  22.  
  23. cpbuild.obj DEPENDS_ON $(H) cpbuild.c
  24.     cc cpbuild.c
  25.  
  26. cpfuncts.obj DEPENDS_ON $(H) cpfuncts.c
  27.     cc cpfuncts.c
  28.  
  29. cpinput.obj DEPENDS_ON $(H) cpinput.c
  30.         cc cpinput.c
  31.  
  32.  
  33. [LISTING TWO]
  34.  
  35. #
  36. # VAX/Unix Makefile 
  37. #
  38. # DEFINITIONS:
  39. #
  40. H = cpheader.h
  41. #
  42. # CP
  43. #
  44. cp : cp.o cpbuild.o cpfuncts.o cpinput.o
  45.     cc -o cp cp.o cpbuild.o cpfuncts.o cpinput.o
  46.  
  47. cp.o : $H cp.c
  48.     cc -c cp.c
  49.  
  50. cpbuild.o : $H cpbuild.c
  51.     cc -c cpbuild.c
  52.  
  53. cpfuncts.o : $H cpfuncts.c
  54.     cc -c cpfuncts.c
  55.  
  56. cpinput.o : $H cpinput.c
  57.     cc -c cpinput.c
  58.  
  59.  
  60. [LISTING THREE]
  61.  
  62. #define MSDOS 0    /* Set the appropriate constant */
  63. #define VMS 0       /* to one (1) before compiling. */
  64. #define UNIX 1       /* All others are zero (0)       */
  65.  
  66.  
  67. [LISTING FOUR]
  68.  
  69. #if VMS
  70. extern int  binary_search_sorted_data_base( char * );
  71. extern void build_box_parts( int );
  72. extern int  build_the_data_base( char * );
  73. extern void check_for_new_page( void );
  74. extern int  doprint( int );
  75. extern void nasty( int );
  76. extern void process_arguments( int, int, char **, int );
  77. extern void scan_for_static_or_global( int *, int, char *, char * );
  78. extern void tab_to_left_margin( FILE * );
  79.  
  80. static void allocate_arrays( void );
  81. static void build_records_from_list( FILE * );
  82. static void bump_line_count( void );
  83. static void count_all_defined_references( void );
  84. static void deallocate_arrays( void );
  85. static void do_top_of_page( void );
  86. static void initialize_globals( void );
  87. static void show_files_leading_comments( void );
  88. static void show_function_relationships( void );
  89. static void show_library_functions( void );
  90. static void show_line_and_byte_counts( void );
  91. static void show_page_references( void );
  92. static void show_sorted_function_list( void );
  93. static void show_unused_if_any( void );
  94. static void sort_the_data_base_array( void );
  95. static char* strdup( char * );
  96. static void timedate( char * );
  97.        int  main( int, char ** );
  98. #endif
  99.  
  100. #if MSDOS
  101. extern int  near binary_search_sorted_data_base( char * );
  102. extern void near build_box_parts( int );
  103. extern int  near build_the_data_base( char * );
  104. extern void near check_for_new_page( void );
  105. extern int  near doprint( int );
  106. extern void near nasty( int );
  107. extern void near process_arguments( int, int, char **, int );
  108. extern void near scan_for_static_or_global( int *, int, char *, char * );
  109. extern void near tab_to_left_margin( FILE * );
  110.  
  111. static void near allocate_arrays( void );
  112. static void near build_records_from_list( FILE * );
  113. static void near bump_line_count( void );
  114. static void near count_all_defined_references( void );
  115. static void near deallocate_arrays( void );
  116. static void near do_top_of_page( void );
  117. static void near initialize_globals( void );
  118. static void near show_files_leading_comments( void );
  119. static void near show_function_relationships( void );
  120. static void near show_library_functions( void );
  121. static void near show_line_and_byte_counts( void );
  122. static void near show_page_references( void );
  123. static void near show_sorted_function_list( void );
  124. static void near show_unused_if_any( void );
  125. static void near sort_the_data_base_array( void );
  126. static char* near strdup( char * );
  127. static void near timedate( char * );
  128.        int  near main( int, char ** );
  129. #endif
  130.  
  131.  
  132.  
  133. [LISTING FIVE]
  134.  
  135. #if MSDOS
  136. static void near bump_line_count( )
  137. #else
  138. static void bump_line_count( )
  139. #endif
  140.  
  141.  
  142. [LISTING SIX]
  143.  
  144. #if MSDOS
  145. #include <malloc.h>
  146. #include <conio.h>
  147. #include <stdlib.h>
  148. #endif
  149.  
  150. #include <ctype.h>  /* this is for the 'tolower' function */
  151. #include <stdio.h>
  152. #include <string.h>
  153.  
  154.  
  155.  
  156. [LISTING SEVEN]
  157.  
  158. #if MSDOS
  159. #include "time.h"
  160. #else
  161. #include <time.h>
  162. #endif
  163.  
  164.  
  165. [LISTING EIGHT]
  166.  
  167. #if !MSDOS
  168. char *strdup(orig)
  169. char *orig;
  170. {
  171.    char *ptr;
  172.  
  173.    ptr = (char *) malloc( (strlen(orig) * sizeof(char)) + 1);
  174.  
  175.    if(ptr != NULL)
  176.    {
  177.       strcpy(ptr,orig);
  178.    }
  179.  
  180.    return(ptr);
  181. }
  182. #endif
  183.  
  184.  
  185. [LISTING NINE]
  186.  
  187.    timedate(title);
  188.  
  189.  
  190. [LISTING TEN]
  191.  
  192. /************************************************************/
  193. #if !MSDOS
  194. static void timedate(ret_time)
  195. char *ret_time;
  196. {
  197.   struct tm *time_structure;
  198.   int time_val, i;
  199.   static char *hour[2] = {"am","pm"};
  200.   char temp[19];
  201.  
  202.   time(&time_val);   
  203.   time_structure = localtime(&time_val); 
  204.  
  205.   i = 0;              
  206.   if((time_structure->tm_hour >= 12)&&(time_structure->tm_hour<24)) i=1;
  207.  
  208.   if(time_structure->tm_hour > 12)
  209.       time_structure->tm_hour = (time_structure->tm_hour)-12;
  210.   sprintf(temp,"%d/%d/%d  %d:%02d %s",
  211.                  time_structure->tm_mon,
  212.                  time_structure->tm_mday,    
  213.                  time_structure->tm_year,
  214.                  time_structure->tm_hour,
  215.                  time_structure->tm_min,
  216.                  hour[i]);
  217.   i=0;
  218.   while(temp[i]!='\0')
  219.   {
  220.      ret_time[i] = temp[i];
  221.      i++;
  222.   }
  223. }
  224. #endif
  225.  
  226. #if MSDOS
  227. static void near timedate(ret_time)
  228. char *ret_time;
  229. {
  230.   char *cp;
  231.   int i;
  232.  
  233.   cp = &ret_time[ 0 ];      /* insert date and nice time into ret_time */
  234.   (void)_strdate( cp );
  235.   ret_time[ 8 ] = ' ';
  236.   cp = &ret_time[ 10 ];
  237.   (void)_strtime( cp );
  238.  
  239.   ret_time[ 15 ] = ' ';   /* knock off seconds */
  240.   ret_time[ 16 ] = ' ';   /* put am, pm here */
  241.   ret_time[ 17 ] = 'm';
  242.   ret_time[ 18 ] = ' ';
  243.  
  244.   i = atoi( &ret_time[ 10 ] );    /* f/ military to civilian time */
  245.   ret_time[ 16 ] = ( i < 12 )? (char)'a': (char)'p';
  246.  
  247.   if( i == 0 )
  248.      i = 12;
  249.   if( i >= 13 )
  250.      i -= 12;
  251.  
  252.   (void)sprintf( &ret_time[ 10 ], "%2d", i );
  253.   ret_time[ 12 ] = ':';
  254.  
  255.   if( ret_time[ 10 ] == '0' )
  256.      ret_time[ 10 ] = ' ';
  257. }
  258. #endif
  259.  
  260. /************************************************************/
  261.  
  262.  
  263. [LISTING ELEVEN]
  264.  
  265.       if(islower((int)argv[i][1]))
  266.      c = argv[i][1];
  267.       else
  268.      c = (char)tolower( (int)argv[ i ][ 1 ] );
  269.  
  270.  
  271. [LISTING TWELVE]
  272.  
  273.    if( strcmp(argv[2],"con") == 0)
  274.       output = stderr;
  275.    else
  276.       output = fopen( argv[ 2 ], "w+" );     /******* wt+ <<<<<<<< ******/
  277.  
  278.  
  279. [LISTING THIRTEEN]
  280.  
  281.    (void)printf( "\n can't open output file.\n");
  282.  
  283.  
  284. [LISTING FOURTEEN]
  285.  
  286. if( (length > 65535) && (MSDOS) )
  287.  
  288.  
  289. [LISTING FIFTEEN]
  290.  
  291. $ CC/PREPROCESS_ONLY CP.C
  292. $ CC/PREPROCESS_ONLY CPBUILD.C
  293. $ CC/PREPROCESS_ONLY CPINPUT.C
  294. $ CC/PREPROCESS_ONLY CPFUNCTS.C
  295. $ CC/PREPROCESS_ONLY CPHEADER.H
  296.  
  297. [LISTING SIXTEEN]
  298.  
  299. cc -E cp.c >cp.i
  300. cc -E cpbuild.c >cpbuild.i
  301. cc -E cpinput.c >cpinput.i
  302. cc -E cpfuncts.c >cpfuncts.i
  303. cc -E cpheader.h >cpheader.i
  304.  
  305. [LISTING SEVENTEEN]
  306.  
  307. cp.i
  308. cpinput.i
  309. cpbuild.i
  310. cpfuncts.i
  311. cpheader.h
  312.  
  313.  
  314.  
  315. [LISTING EIGHTEEN]
  316.  
  317. #define  LEN_INFILE  256
  318.  
  319.  
  320.  
  321.  
  322. [LISTING NINETEEN]
  323.  
  324. char input_list_filename[ LEN_INFILE ], input_line[ LEN_INFILE ];
  325. char overlay_number[ LEN_INFILE ];
  326.  
  327.  
  328. [LISTING TWENTY]
  329.  
  330. fgets( input_line, LEN_INFILE-1, stream );   /* ends at \n or eof */
  331.  
  332.  
  333. [LISTING TWENTY-ONE]
  334.     
  335. Replaces line 20 of Listing Five
  336.  
  337.    *top_line_of_box, *bottom_line_of_box,
  338.  
  339.  
  340. [LISTING TWENTY-TWO]
  341.  
  342. Replaces lines 73 thru 75 of Listing Five
  343.     
  344. if( !( top_line_of_box =(char *)malloc( defined_box_width * sizeof(char) ))
  345.   )
  346. {
  347.    (void)fprintf( stderr, "Ran out of memory for top line of box.\n" );
  348.    exit( 1 );
  349. }
  350.  
  351. if( !( bottom_line_of_box =(char *)malloc( defined_box_width * sizeof(char) ))
  352.   )
  353. {
  354.    (void)fprintf( stderr, "Ran out of memory for bottom line of box.\n" );
  355.    exit( 1 );
  356. }
  357.  
  358. top_line_of_box[ 0 ] = upper_left_corner;   
  359. bottom_line_of_box[ 0 ] = lower_left_corner;
  360. for( i = 1; i <= (defined_box_width - 3); ++i )
  361.  
  362.  
  363. [LISTING TWENTY-THREE]
  364.  
  365. Replaces lines 215 and 216 of Listing Five
  366.  
  367.                     name_of_file,
  368.                     description,
  369.  
  370.  
  371.  
  372. [LISTING TWENTY-FOUR]
  373.  
  374. Replaces lines 228 thru 274 of Listing Five
  375.  
  376. unsigned int string_length;
  377. int x;
  378. static char alternate_lead_in[ 140 ];
  379.  
  380. /******* 1st line *****************************************************/
  381. tab_to_left_margin( output );
  382. (void)fprintf( output, "%s %s\n", lead_in_string, top_line_of_box );
  383.  
  384. /******* 2nd line ******************************************************/
  385. tab_to_left_margin( output );
  386. string_length = strlen( lead_in_string );
  387. if( string_length )    /******* ie not main or defined function box ***/
  388.    {
  389.    (void)strncpy( alternate_lead_in, lead_in_string, --string_length );
  390.    alternate_lead_in[ string_length++ ] = '\0'; /*restore string_length*/
  391.    }
  392. if( string_length )   /******* ie not main or defined function box ***/
  393.    {
  394.    if( g_ov_flag && ov_num )
  395.       {
  396.       (void)fprintf( output, "%s%c%c%c%s %3d",
  397.              alternate_lead_in,
  398.       /***  if( kill_flag )   /****** last line to this box ******************/
  399.       /***  else          /****** line continues downwards ***************/
  400.              ( kill_flag )? lower_left_corner: right_attach,
  401.              ibm_line, left_attach, name_of_function, ov_num);
  402.       for(x=strlen(name_of_function);x < defined_box_width-7;x++)
  403.      putc(' ',output);
  404.       putc(wall,output);
  405.       putc('\n',output);
  406.       }
  407.    else
  408.       {
  409.       (void)fprintf( output, "%s%c%c%c%s    ",
  410.              alternate_lead_in,
  411.       /***  if( kill_flag )   /****** last line to this box ******************/
  412.       /***  else          /****** line continues downwards ***************/
  413.              ( kill_flag )? lower_left_corner: right_attach,
  414.              ibm_line, left_attach, name_of_function);
  415.       for(x=strlen(name_of_function);x < defined_box_width-7;x++)
  416.      putc(' ',output);
  417.       putc(wall,output);
  418.       putc('\n',output);
  419.       }
  420.    }
  421. else             /****** main or defined box starting ***********/
  422.    {
  423.    if( g_ov_flag && ov_num )
  424.       {
  425.       (void)fprintf( output,     "%c%c%s %3d",
  426.              ibm_line, left_attach, name_of_function, ov_num);
  427.       for(x=strlen(name_of_function);x < defined_box_width-7;x++)
  428.      putc(' ',output);
  429.       putc(wall,output);
  430.       putc('\n',output);
  431.       }
  432.    else
  433.       {
  434.       (void)fprintf( output,     "%c%c%s    ",
  435.              ibm_line, left_attach, name_of_function);
  436.       for(x=strlen(name_of_function);x < defined_box_width-7;x++)
  437.      putc(' ',output);
  438.       putc(wall,output);
  439.       putc('\n',output);
  440.       }
  441.    }
  442. /******* 3rd line *****************************************************/
  443. tab_to_left_margin( output );
  444. if( string_length-- )     /** kill outside vertical line on last box **/
  445.    lead_in_string[ string_length++ ] = ( kill_flag )? (char)' ': wall;
  446. (void)fprintf( output, "%s %c%s   %8s%3d",
  447.            lead_in_string, wall,  name_of_file, description, either_count);
  448.    for(x=strlen(name_of_file);x < defined_box_width-17;x++) putc(' ',output);
  449.    putc(wall,output);
  450.    putc('\n',output);
  451.  
  452.  
  453. [LISTING TWENTY-FIVE]
  454.  
  455. Insert between 109 and 110 of Listing One
  456.  
  457.    defined_box_width =       40,
  458.  
  459.  
  460. [LISTING TWENTY-SIX]
  461.  
  462. Insert between 160 and 161 of Listing One
  463.  
  464. extern int defined_box_width;
  465.  
  466.  
  467. [LISTING TWENTY-SEVEN]
  468.  
  469. Replaces lines 20 through 25 of Listing Three
  470.  
  471.     "     /p:nn /w:nn /m:nn /r:nn /t:main /f:nnnn /b:nn\n"
  472.            );
  473.    (void)printf(
  474.    "     /l /n /s /q /d /o /u /c /h /x\n"
  475.            );
  476.    (void)printf(   "                        ]\n" );
  477.  
  478.  
  479.  
  480. [LISTING TWENTY-EIGHT]
  481.  
  482. Insert between 45 and 46 of Listing Three
  483.  
  484.    (void)printf(
  485.    "     b: width of func. box  = %2d    [ 20 - 255 ]\n", defined_box_width
  486.            );
  487.  
  488.  
  489. [LISTING TWENTY-NINE]
  490.  
  491. Insert between 155 and 156 of Listing Three                                           
  492.  
  493.                                            
  494.           case 'b':                
  495.              if( ( 20 < tmp ) && ( tmp < 255 ) )
  496.             defined_box_width = tmp;
  497.              break;                
  498.  
  499.  
  500.  
  501.  
  502.  
  503.